// pageMerchant/goodsInfo/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl:app.globalData.imgUrl,
    buyShow: false
  },
  onLoad(options){
    let str=options.info
    if(str){
      let device=JSON.parse(str)
      if(device.picture){
        if(device.picture.includes(',')){
          let list=device.picture.split(',')
          let ss=[]
          list.forEach(element => {
            element=this.data.imgUrl+element
            ss.push(element)
          });
          device.imgList=ss
        }else{
          device.imgList=[this.data.imgUrl+device.picture]
        }
    }
      this.setData({info:device})
    }
  },
  // 图片预览
preview (e) {
  wx.previewImage({
    urls: this.data.info.imgList,
    current: e.currentTarget.dataset.url,
  })
},
//打开入库弹窗
  buy () {
    this.setData({ buyShow: true })
  },
  // 关闭入库弹窗
  onClose(){
    this.setData({ buyShow: false })
  },
  // 订单入库
  toBuy(){
    let that=this
        wx.$req({
          url: '/wms/orderPurchase/in',
          loadingText: '加载中...',
          data:{id:this.data.info.id},
          method:"Put"
        }).then(res => {
            if(res.data.code==500){
              wx.showToast({
                title: res.data.msg,
                icon: 'none'
              })
            }else{
              wx.showToast({
                title: '收货成功',
                icon: 'success'
              })
              wx.navigateBack()
            }
          })
  }

})